package com.exsun.gateway.jt809.kafka.gps;

import com.exsun.gateway.jt809.codec.protocol.Jt809Encode;
import com.exsun.gateway.jt809.data.Interface.IGpsHandle;
import com.exsun.gateway.jt809.data.PushData;
import com.exsun.gateway.jt809.handler.SendMgrHandler;
import com.exsun.gateway.jt809.kafka.JT809KafkaGpsDataHandler;
import exsun.jt808.data.config.jt809.Jt809MsgIdConfig;
import exsun.jt808.data.jt809_data.BasicVehicleInfo;
import exsun.jt808.data.jt809_data.vehicledynamic.GnssData;
import exsun.jt808.data.jt809_data.vehicledynamic.main.UpExgMsgRealLocation;
import exsun.jt808.data.upload_data.GpsData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;

public class RealLocation implements IGpsHandle<UpExgMsgRealLocation> {
    private Logger logger = LoggerFactory.getLogger(RealLocation.class);

    @Autowired
    Jt809Encode jt809Encode;
    /**
     * 组包
     * @param data
     * @param sendMgrHandler
     * @return
     */
    @Override
    public List<PushData> getPushData(UpExgMsgRealLocation data, SendMgrHandler sendMgrHandler) {
        byte[] body = sendMgrHandler.jt809Encode.UpExgMsgRealLocation(data,Jt809MsgIdConfig.UP_EXG_MSG_REAL_LOCATION);
        PushData pushData = new PushData(Jt809MsgIdConfig.UP_EXG_MSG, body);

        List<PushData> pushs = new ArrayList<>();
        pushs.add(pushData);
        return pushs;
    }

    /**
     * 数据转换
     * 实时上传车辆定位 上级平台无需应答
     * @param positionInfo
     * @param basicVehicleInfo
     * @return
     */
    @Override
    public UpExgMsgRealLocation convert(GpsData positionInfo, BasicVehicleInfo basicVehicleInfo) {
        GnssData gnssData = GpsConvert.gnssDataHandle(positionInfo);
        UpExgMsgRealLocation upExgMsgRealLocation = new UpExgMsgRealLocation();
        upExgMsgRealLocation.setBasicVehicleInfo(basicVehicleInfo);
        upExgMsgRealLocation.setGnssData(gnssData);
        logger.info("实时数据：{},{}", basicVehicleInfo.getVehicleNo(), gnssData.toString());
        return upExgMsgRealLocation;
    }
}
